package Game.Objects;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import GUI.GuiManager;
import Game.GameHelper;
import Game.Items.GameItem;
import Game.Items.Armors.Boots.GIBoneBoots;
import Game.Items.Armors.Boots.GIRustyBoots;
import Game.Items.Armors.Boots.GISteelBoots;
import Game.Items.Armors.Chestplates.GIBoneChestplate;
import Game.Items.Armors.Chestplates.GIRustyChestplate;
import Game.Items.Armors.Chestplates.GISteelChestplate;
import Game.Items.Armors.Gloves.GIBoneGloves;
import Game.Items.Armors.Gloves.GIRustyGloves;
import Game.Items.Armors.Gloves.GISteelGloves;
import Game.Items.Armors.Helmets.GIBoneHelmet;
import Game.Items.Armors.Helmets.GIRustyHelmet;
import Game.Items.Armors.Helmets.GISteelHelmet;
import Game.Items.Armors.Shields.GIBoneShield;
import Game.Items.Armors.Shields.GIRustyShield;
import Game.Items.Armors.Shields.GISteelShield;
import Game.Items.Craft.GIApple;
import Game.Items.Craft.GICarrot;
import Game.Items.Craft.GIChickenLeg;
import Game.Items.Craft.GIPotato;
import Game.Items.Others.GIMap;
import Game.Items.Others.GITorch;
import Game.Items.Others.GITreasureMap;
import Game.Items.Potions.GIAntipoisonPotion;
import Game.Items.Potions.GIBigHealthPotion;
import Game.Items.Potions.GIMediumHealthPotion;
import Game.Items.Potions.GIMydriasisPotion;
import Game.Items.Potions.GISmallHealthPotion;
import Game.Items.Potions.GIStrengthPotion;
import Game.Items.Weapons.GISteelSword;

/** Seller class
 * @author Aikidos
 */
public class GOSeller extends GameObject {

	/** List of item */
	private List<GameItem> _lstItems = new ArrayList<GameItem>();
	
	/** Number of items */
	private int _numOfItems = 10;
	
	public GOSeller(ObjectManager objectManager) throws SlickException {
		super(objectManager, "Seller");
		
		setSprite(new Image("res/gfx/creatures/seller.png"));
	
		_isCanBeUsed = true;
		
		// Add items to temp list
		List<GameItem> lstTemp = new ArrayList<GameItem>();
		
		// Armors
		lstTemp.add(new GIRustyBoots());
		lstTemp.add(new GIBoneBoots());
		lstTemp.add(new GISteelBoots());
		lstTemp.add(new GIRustyGloves());
		lstTemp.add(new GIBoneGloves());
		lstTemp.add(new GISteelGloves());
		lstTemp.add(new GIRustyHelmet());
		lstTemp.add(new GIBoneHelmet());
		lstTemp.add(new GISteelHelmet());
		lstTemp.add(new GIRustyChestplate());
		lstTemp.add(new GIBoneChestplate());
		lstTemp.add(new GISteelChestplate());
		lstTemp.add(new GIRustyShield());
		lstTemp.add(new GIBoneShield());
		lstTemp.add(new GISteelShield());
		
		// Weapons
		lstTemp.add(new GISteelSword());
		
		// Potions
		lstTemp.add(new GISmallHealthPotion());
		lstTemp.add(new GIMediumHealthPotion());
		lstTemp.add(new GIAntipoisonPotion());
		lstTemp.add(new GIBigHealthPotion());
		lstTemp.add(new GIMydriasisPotion());
		lstTemp.add(new GIStrengthPotion());
		
		// Other
		lstTemp.add(new GITreasureMap());
		lstTemp.add(new GIMap());
		lstTemp.add(new GITorch());
		lstTemp.add(new GIChickenLeg());
		lstTemp.add(new GIApple());
		lstTemp.add(new GICarrot());
		lstTemp.add(new GIPotato());
		
		// Add random items to list of item
		Random rnd = GameHelper.getRandom();
		
		for (int i = 0; i < _numOfItems; i++) {
			if (lstTemp.size() == 0) break;
			
			int index = rnd.nextInt(lstTemp.size());
			_lstItems.add(lstTemp.get(index));
			
			lstTemp.remove(index);
		}
		
		
		
	}
	
	/** Returns list of item
	 * @return List of item
	 */
	public List<GameItem> getItems() {
		return _lstItems;
	}

	@Override
	public void use(GameObject user) throws SlickException,
			InstantiationException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		
		if (user.isPlayer())
			if (!GuiManager.isAnyOpen())
				GuiManager.getGuiSeller().open(this);
	}
	
}
